package com.rim.samples.device.helloworlddemo;

import java.io.ByteArrayInputStream;
import java.io.IOException;

public class MyInputStream extends ByteArrayInputStream
{
    
    private byte[] packetData;
    
    public MyInputStream(byte[] buf)
    {
        super(buf);
    }
   
    public synchronized int available()
    {
        int re = super.available();
        System.out.println( "available()" + "return:" + Integer.MAX_VALUE);
        return Integer.MAX_VALUE;
    }

    public synchronized void close() throws IOException
    {
        System.out.println( "close()");
        super.close();
    }

    public void mark(int readAheadLimit)
    {
        System.out.println( "mark(int readAheadLimit)");
        super.mark(readAheadLimit);
    }

    public boolean markSupported()
    {
        System.out.println( "markSupported()");
        return super.markSupported();
    }

    public synchronized int read()
    {
        int re = super.read();
        System.out.println( "read()" + " return:" + re);
        return re;
    }

    /**
     * 
     */
    public synchronized int read(byte[] b, int offset, int length)
    {
        System.out.println("===read===" + " length:" + length);

        packetData = new byte[length];

        System.arraycopy(packetData, 0, b, offset, length);

        return length;
    }
    
    public synchronized void reset()
    {
        System.out.println( "reset()");
        super.reset();
    }

    public synchronized long skip(long n)
    {
        long re = super.skip(n);
        System.out.println( "long skip(long n)" + " arg:" + "n=" + n + "  return: " + re);
        return re;
    }

    public int read(byte[] arg0) throws IOException
    {
        int re = super.read(arg0);
        System.out.println( "read(byte[] arg0)" + " arg:" + " arg0=" + arg0
            + "  return:" + re);
        return re;
    }

}
